package com.marquis.cloud.controller;

import com.marquis.cloud.config.pagequery.PaginationGrid;
import com.marquis.cloud.entity.AutUser;
import com.marquis.cloud.service.AutUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/aut/user/")
public class AutUserController {

    @Autowired
    private AutUserService userService;

    /**
     * 分页查询用户信息
     * @param request 请求
     * @param page 分页信息, pageSize=0时，查询所有数据
     * @return
     */
    @RequestMapping(value = "queryUserPage")
    public PaginationGrid<AutUser> queryUserPage(HttpServletRequest request, PaginationGrid<AutUser> page){
        page = userService.queryUserPage(page);
        for (AutUser user : page.getRows()) {
            user.setProviderURL(request.getRequestURL().toString());
        }
        return page;
    }

    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    @RequestMapping(value = "findByUserName")
    public AutUser findByUserName(String userName){
        return userService.findByUserName(userName);
    }

}
